package cn.kshost.zqyg.product.service.impl;

import cn.kshost.zqyg.model.entity.product.Category;
import cn.kshost.zqyg.product.helper.CategoryTreeHelper;
import cn.kshost.zqyg.product.mapper.CategoryMapper;
import cn.kshost.zqyg.product.service.CategoryService;
import com.alibaba.fastjson2.JSON;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.concurrent.TimeUnit;
@Transactional(rollbackFor = Exception.class)
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    RedisTemplate<String,String> redisTemplate;
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    @Cacheable(value = "category",key = "'all'")
    public List<Category> getCategoryList() {

        List<Category> categoryList =  categoryMapper.selectAllCategory();
        //构建树节点
        List<Category> categories = CategoryTreeHelper.buildTree(categoryList);
        return categories;
    }

    @Override
    @Cacheable(value = "category",key = "'root'")
    public List<Category> getRootCategoryList() {
        return categoryMapper.selectRootCategory();
    }
}
